import configparser


class Config:
	# 初始化配置，加载config.ini文件
	def __init__(self, config_file=r'F:\Study\Project\EduRAGProject\config.ini'):
		# 创建配置解析器
		self.config = configparser.ConfigParser()
		# 读取配置文件
		self.config.read(config_file, encoding='utf-8')  # windows包gbk错误，=增加encoding=utf-8

		# MySQL配置
		# MySQL主机地址
		self.MYSQL_HOST = self.config.get('mysql', 'host', fallback='localhost')

		# MySQL用户名
		self.MYSQL_USER = self.config.get('mysql', 'user', fallback='root')
		# MySQL密码
		self.MYSQL_PASSWORD = self.config.get('mysql', 'password', fallback='123456')
		# MySQL数据库名
		self.MYSQL_DATABASE = self.config.get('mysql', 'database', fallback='subjects_kg')

		# Redis配置
		# Redis主机地址
		self.REDIS_HOST = self.config.get('redis', 'host', fallback='localhost')
		# Redis端口
		self.REDIS_PORT = self.config.get('redis', 'port', fallback=6379)
		# Redis密码
		self.REDIS_PASSWORD = self.config.get('redis', 'password', fallback='1234')
		# Redis数据库编号
		self.REDIS_DB = self.config.getint('redis', 'db', fallback=0)

		# milvus配置
		# milvus主机地址
		self.MILVUS_HOST = self.config.get('milvus', 'host', fallback='192.168.40.110')
		# milvus端口
		self.MILVUS_PROT = self.config.get('milvus', 'prot', fallback=19530)
		# milvus数据库名
		self.MILVUS_DATABASE_NAME = self.config.get('milvus', 'database_name', fallback='education')
		# milvus集合名
		self.MILVUS_COLLECTION_NAME = self.config.get('milvus', 'collection_name', fallback='edurag_final')

		# LLM配置
		self.LLM_MODEL = self.config.get('llm', 'model')
		# DeepSeek API秘钥
		self.DEEPSEEK_API_KEY = self.config.get('llm', 'deepseek_api_key')
		# DeepSeek API地址
		self.DEEPSEEK_BASE_URL = self.config.get('llm', 'deepseek_base_url')

		# 检索参数
		# 父块大小
		self.PARENT_CHUNK_SIZE = self.config.getint('retrieval', 'parent_chunk_size')
		# 子块大小
		self.CHILD_CHUNK_SIZE = self.config.getint('retrieval', 'child_chunk_size')
		# 块重叠大小
		self.CHUNK_OVERLAP = self.config.getint('retrieval', 'chunk_overlap')
		# 检索返回数量
		self.RETRIEVAL_K = self.config.getint('retrieval', 'retrieval_k')
		# 最终候选数量
		self.CANDIDATE_M = self.config.getint('retrieval', 'candidate_m')

		# 应用配置
		# 有效来源列表
		self.VALID_SOURCES = eval(
			self.config.get('app', 'valid_source', fallback="['ai', 'java', 'test', 'ops', 'bigdata']")
		)
		# 客服电话
		self.CUSTOMER_SERVICE_PHONE = self.config.get('app', 'customer_service_phone', fallback='400-123-4567')
		# 日志文件路径
		self.LOG_FILE = self.config.get('logger', 'log_file', fallback='logs/app.log')


if __name__ == '__main__':
	conf = Config()
	print(conf.CHILD_CHUNK_SIZE)
